/**
 * 报表设计公司(2011)
 */
package net.abbp.report.designer.action.file;

import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import net.abbp.report.context.ReportContext;
import net.abbp.report.model.ReportModel;
import net.abbp.report.view.GridView;

import net.abbp.swing.util.ImageUtils;
import net.abbp.core.util.StringUtils;
import com.reportgear.designer.action.ReportAction;
import com.reportgear.report.model.calculator.CalculatorHelper;
import com.reportgear.report.print.Printer;
import com.reportgear.report.print.ReportPage;
import com.reportgear.report.print.ReportPageIterator;

/**
 * @version 1.0 2011-3-24
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since ANNCSR 2.0
 */
public class PrintReportAction extends ReportAction {

    public PrintReportAction() {
        setName("打印");
        setSmallIcon(ImageUtils.readIcon("file/print.png"));
    }

    public void actionPerformed(ActionEvent e) {
        GridView gridView = ReportContext.INSTANCE.getCurrentView();
        ReportModel report = gridView.getReportModel();

        ReportModel currReport = CalculatorHelper.calResumeModel(report, StringUtils.convertToString(
                ReportContext.INSTANCE.getBusItem("PersonId"), "0"));

        List<ReportPage> pages = new ArrayList<ReportPage>();
        Iterator<ReportPage> rs = new ReportPageIterator(currReport);
        while (rs.hasNext()) {
            pages.add(rs.next());
        }
        new Printer().print(pages);
    }
}
